#include "pagevehiclesidenavi.h"
#include "ui_pagevehiclesidenavi.h"

PageVehicleSideNavi::PageVehicleSideNavi(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageVehicleSideNavi)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    m_lNaviBtnName<<"牵引系统"
                  <<"制动系统"
                  <<"辅助系统"
                  <<"蓄电池"
                  <<"烟温系统"
                  <<"紧急对讲";
    InitBtns();
}

PageVehicleSideNavi::~PageVehicleSideNavi()
{
    delete ui;
}

void PageVehicleSideNavi::InitBtns()
{
    uint8_t navibtncnt = m_lNaviBtnName.length();
    m_nNaviBtnLen = 110;
    m_nNaviBtnHeight = 50;
    m_nVSpace = 15;
    m_nStartx = (this->width()-m_nNaviBtnLen)/2;
    m_nStarty = 10;

    for(uint i=0;i<navibtncnt;i++)
    {
        QPushButton *btn = new QPushButton(this);
        btn->setStyleSheet(SideNaviBtnStyle);
        btn->setGeometry(m_nStartx,m_nStarty+i*(m_nNaviBtnHeight+m_nVSpace),
                         m_nNaviBtnLen,m_nNaviBtnHeight);
        btn->setText(m_lNaviBtnName.at(i));
        btn->setCheckable(true);
        btn->setChecked(i==0);
        m_cNaviBtnGroup.addButton(btn,i+Page_Vehcile_Traction);
    }
    connect(&m_cNaviBtnGroup,SIGNAL(buttonClicked(int)),this,SIGNAL(signal_show_vehicle_page(int)));
}

void PageVehicleSideNavi::setBtnChecked(int id)
{
    QAbstractButton* btnChecked = m_cNaviBtnGroup.checkedButton();
    btnChecked->setChecked(false);
    QAbstractButton* firstBtn = m_cNaviBtnGroup.button(id);
    firstBtn->setChecked(true);
}
